package cn.tedu.hhmc.patient.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import cn.tedu.hhmc.base.response.JsonResult;
import cn.tedu.hhmc.patient.pojo.dto.PatientDTO;
import cn.tedu.hhmc.patient.pojo.dto.PatientRelativesParam;
import cn.tedu.hhmc.patient.pojo.entity.Patient;
import cn.tedu.hhmc.patient.pojo.vo.PatientVO;
import cn.tedu.hhmc.patient.service.IPatientService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 病人信息Controller
 *
 * @author ruoyi
 * @date 2024-12-05
 */
@Slf4j
@RestController
@RequestMapping("/hhmc/patient")
public class PatientController
{
    @Autowired
    private IPatientService patientService;

    /**
     * 查询病人信息列表
     */
    @GetMapping("/list")
    public JsonResult list()
    {
        log.debug("查询所有病人信息列表,参数:无");
        List<PatientVO> list = patientService.selectPatientList(new Patient());
        return JsonResult.ok(list);
    }

    /**
     * 获取病人信息详细信息
     */
    @GetMapping(value = "/select/{id}")
    public JsonResult getInfo(@PathVariable("id") Long id)
    {
        log.debug("查询病人信息列表,参数:{}",id);
        return JsonResult.ok(patientService.selectPatientById(id));
    }

    /**
     * 获取病人家属信息
     */
    @GetMapping(value = "/getFamilyInfo/{id}")
    public JsonResult getFamilyInfo(@PathVariable("id") Long id)
    {
        log.debug("查询病人家属信息,参数:{}",id);
        return JsonResult.ok(patientService.getFamilyInfoById(id));
    }
    /**
     * 新增病人信息
     */
    @PostMapping(value = "/addFamilyMember")
    public JsonResult addFamilyMember(PatientRelativesParam patientRelativesParam)
    {
        patientService.addFamilyMember(patientRelativesParam);
        return JsonResult.ok();
    }

    /**
     * 修改病人信息
     */
    @PostMapping(value = "/insert")
    public JsonResult insert(PatientDTO patientDTO)
    {
        patientService.insertPatient(patientDTO);
        return JsonResult.ok();
    }

    @PostMapping(value = "/update")
    public JsonResult update(PatientDTO patientDTO)
    {
        patientService.updatePatient(patientDTO);
        return JsonResult.ok();
    }

    /**
     * 删除病人信息
     */
    @DeleteMapping("/{ids}")
    public JsonResult remove(@PathVariable Long[] ids)
    {
        patientService.deletePatientByIds(ids);
        return JsonResult.ok();
    }
}
